#include <iostream>
#include <stack>
#include <unordered_map>

bool isValidBracketSequence(const std::string& sequence) {
    std::stack<char> bracketStack;
    std::unordered_map<char, char> bracketPairs = {
        {'(', ')'},
        {'[', ']'},
        {'{', '}'},
        {'<', '>'}
    };

    for (char bracket : sequence) {
        if (bracketPairs.find(bracket) != bracketPairs.end()) {
            bracketStack.push(bracket);
        } else if (bracketPairs[bracketStack.top()] == bracket) {
            bracketStack.pop();
        } else {
            return false;
        }
    }

    return bracketStack.empty();
}

int main() {
    std::string inputSequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> inputSequence;

    bool result = isValidBracketSequence(inputSequence);
    std::cout << std::boolalpha << result << std::endl;

    return 0;
}
